/*
QAuthentee
Copyright (C) 2010  Pavel Mynarsky <admin@akia.se>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "displaywidget.h"
#include <QDebug>

DisplayWidget::DisplayWidget(QWidget *parent) : QFrame(parent)
{
    setGeometry(QRect(110, 30, 120, 80));
    setFrameShape(QFrame::StyledPanel);
    setFrameShadow(QFrame::Sunken);
    setBackgroundRole(QPalette::Base);
    setAutoFillBackground(true);

    leftHand = new QSvgWidget(":/images/left.svg", this);
    leftHand->setGeometry(10, 8 , HAND_WIDTH, HAND_HEIGHT);

    rightHand = new QSvgWidget(":/images/right.svg", this);
    rightHand->setGeometry(160, 8, HAND_WIDTH, HAND_HEIGHT);

    fingers = new QFingerPushButton*[10];
    for(int i = 0; i < 10; i++)
        fingers[i] = new QFingerPushButton(this);

    fingers[5]->setSkin("r_0");
    fingers[5]->setGeometry(163, 90, 32, 26);

    fingers[6]->setSkin("r_1");
    fingers[6]->setGeometry(191, 28, 35, 51);

    fingers[7]->setSkin("r_2");
    fingers[7]->setGeometry(226, 15, 15, 63);

    fingers[8]->setSkin("r_3");
    fingers[8]->setGeometry(247, 31, 19, 56);

    fingers[9]->setSkin("r_4");
    fingers[9]->setGeometry(263, 62, 28, 37);

    fingers[0] ->setSkin("l_0");
    fingers[0] ->setGeometry(110, 90, 32, 26);

    fingers[1]->setSkin("l_1");
    fingers[1]->setGeometry(77, 28, 35, 51);

    fingers[2]->setSkin("l_2");
    fingers[2]->setGeometry(65, 15, 14, 63);

    fingers[3]->setSkin("l_3");
    fingers[3]->setGeometry(40, 31, 18, 56);

    fingers[4]->setSkin("l_4");
    fingers[4]->setGeometry(14, 62, 28, 37);

    mapperEnroll = new QSignalMapper(this);
    mapperVerify = new QSignalMapper(this);
    mapperRemove = new QSignalMapper(this);
    mapperClicked = new QSignalMapper(this);

    for(int i = 0; i < 10; i++)
    {
        mapperEnroll->setMapping(fingers[i], i + 1);
        mapperVerify->setMapping(fingers[i], i + 1);
        mapperRemove->setMapping(fingers[i], i + 1);
        mapperClicked->setMapping(fingers[i], i + 1);

        connect(fingers[i], SIGNAL(enroll()), mapperEnroll, SLOT(map()));
        connect(fingers[i], SIGNAL(verify()), mapperVerify, SLOT(map()));
        connect(fingers[i], SIGNAL(remove()), mapperRemove, SLOT(map()));
        connect(fingers[i], SIGNAL(clicked()), mapperClicked, SLOT(map()));
    }
    connect(mapperEnroll, SIGNAL(mapped(int)), this, SIGNAL(enroll(int)));
    connect(mapperVerify, SIGNAL(mapped(int)), this, SIGNAL(verify(int)));
    connect(mapperRemove, SIGNAL(mapped(int)), this, SIGNAL(remove(int)));
    connect(mapperClicked, SIGNAL(mapped(int)), this, SIGNAL(clicked(int)));
}

void DisplayWidget::markEnrolledFingerprints(int fingerprint, bool enrolled)
{
    fingers[fingerprint]->setEnrolled(enrolled);
    update();
}
